using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Reflection;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Awaken.Framework;
using Northwind.Domain.Entities;

namespace Northwind.Web.Controls
{
    public partial class TypeSelectorControl : System.Web.UI.UserControl
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!Page.IsPostBack)
            {
                typeDropDownList.DataSource = Gateway.MappedTypes;
                typeDropDownList.DataBind();
            }
        }

        protected void loadButton_OnClick(object s, System.EventArgs e)
        {
            Assembly assembly = Assembly.Load("Northwind.Domain");

            string brokerTypeName = "Northwind.Domain.Entities." + typeDropDownList.SelectedValue + "Broker";

            Type brokerType = assembly.GetType(brokerTypeName);

            object broker = Activator.CreateInstance(brokerType);
            
            IBroker impl = (IBroker)broker;

            entityGrid.DataSource = impl.GetAll();
            entityGrid.DataBind();
        }
    }
}